﻿// <copyright file="AppNotificationTestSenderFactory.cs" company="Robert Venables">
// Copyright (c) 2009 Robert Venables.
// </copyright>
// <author>Robert Venables</author>
// <email>rob@rvenables.com</email>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VNotify;

namespace VNotifyTest.Mock
{
    /// <summary>
    /// AppNotification sender factory which builds test senders.
    /// </summary>
    internal class AppNotificationTestSenderFactory 
        : AppNotificationSenderFactory<AppNotificationTestSender>
    {
        #region IAppNotificationSenderFactory Members

        /// <summary>
        /// Initializes a new instance of the AppNotificationTestSenderFactory class.
        /// </summary>
        public AppNotificationTestSenderFactory()
        {
            AppNotificationTestSender.SendCount = 0;
        }

        /// <summary>
        /// Gets the last constructed AppNotificationTestSender.
        /// (Allows test methods to access the last created sender.)
        /// </summary>
        public AppNotificationTestSender LastConstructedSender { get; private set; }

        /// <summary>
        /// Gets or sets an exception that should be thrown by the generated
        /// senders.
        /// </summary>
        public Exception InjectedSimulatedException { get; set; }

        /// <summary>
        /// Builds a new (Test) sender.
        /// </summary>
        /// <param name="apiKey">The test API key to use.</param>
        /// <returns>A new test app notification sender.</returns>
        public override IAppNotificationSender BuildSender(string apiKey)
        {
            Assert.IsFalse(string.IsNullOrEmpty(apiKey));
            Console.WriteLine("AppNotificationTestSenderFactory: BuildSender()");
            AppNotificationTestSender currentSender
                = (AppNotificationTestSender)base.BuildSender(apiKey);

            currentSender.SimulatedException = this.InjectedSimulatedException;
            
            this.LastConstructedSender = currentSender;

            return currentSender;
        }

        #endregion
    }
}